package com.ylbh.modules.shoppingegg.service.Impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylbh.common.pojo.egg.dto.ShoppingEggDTO;
import com.ylbh.common.pojo.egg.vo.UpgradeSettingVO;
import com.ylbh.common.utils.IdWorker;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.ShiroUtils;
import com.ylbh.modules.shoppingegg.entity.ShoppingEgg;
import com.ylbh.modules.shoppingegg.mapper.ShoppingEggMapper;
import com.ylbh.modules.shoppingegg.service.ShoppingEggService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Service
public class ShoppingEggServiceImpl implements ShoppingEggService {

    @Autowired
    private ShoppingEggMapper shoppingEggMapper;
    @Override
    public PageUtils queryGoodsEggList(ShoppingEggDTO shoppingEggDTO) {

        Page<Object> page = new Page<>(shoppingEggDTO.getPage(),shoppingEggDTO.getLimit());
        List<ShoppingEgg> list = shoppingEggMapper.selectGoodsEggList(shoppingEggDTO,page);
        Page<ShoppingEgg> page1 = new Page<>();
        page1.setRecords(list).setTotal(page.getTotal());
        return new PageUtils(page1);
    }

    @Override
    public List<UpgradeSettingVO> getUpgradeInfo() {
        return shoppingEggMapper.selectUpgradeInfo();
    }

    @Override
    public void addUpgradeInfo(ShoppingEggDTO shoppingEggDTO) {
        ShoppingEgg egg = new ShoppingEgg();
        IdWorker idW = new IdWorker();
        Date date = new Date();
        egg.setId(idW.nextId());
        egg.setCreateTime(date);
        egg.setUpdateTime(date);
        egg.setJumpType(shoppingEggDTO.getJumpType());
        egg.setKeyWord(shoppingEggDTO.getKeyWord());
        egg.setRemarks(shoppingEggDTO.getRemarks());
        egg.setJumpUrl(shoppingEggDTO.getJumpUrl());
        egg.setSysUserId(ShiroUtils.getUserId().toString());
        shoppingEggMapper.insertUpgradeInfo(egg);
    }

    @Override
    public ShoppingEgg getUpgradeById(String id) {
        return shoppingEggMapper.selectUpgradeById(id);
    }

    @Override
    public void modifyUpgradeInfo(ShoppingEggDTO shoppingEggDTO) {
        ShoppingEgg egg = new ShoppingEgg();
        egg.setId(shoppingEggDTO.getId());
        egg.setUpdateTime(new Date());
        egg.setJumpType(shoppingEggDTO.getJumpType());
        egg.setKeyWord(shoppingEggDTO.getKeyWord());
        egg.setRemarks(shoppingEggDTO.getRemarks());
        egg.setJumpUrl(shoppingEggDTO.getJumpUrl());
        egg.setSysUserId(ShiroUtils.getUserId().toString());
        shoppingEggMapper.updateUpgradeInfo(egg);
    }

    @Override
    public void removeEggByIds(String id) {
        shoppingEggMapper.deleteEggById(id);
    }

    @Override
    public void modifyEggStateByIds(String batchValue, String[] ids) {
        shoppingEggMapper.updataEggStateByIds(batchValue, Arrays.asList(ids));
    }

    @Override
    public void modifyEggStateById(ShoppingEggDTO shoppingEggDTO) {
        shoppingEggMapper.updataEggStateById(shoppingEggDTO);
    }
}
